<!DOCTYPE html>
<html lang="en" >
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="author" content="GoJun" />
	
	
	
	<title>如何利用 frp 实现 Mac 的内网穿透 ｜ GoJun</title>
	
    
    
    <meta name="description" content="这里服务端我用的是阿里云的轻量应用服务器，系统配置的 Ubuntu18.04；客户端是自己开发的 Mac 电脑。 下面记录的是如何利用 frp 来实现本地的 web 端口可以使用外网来访问。 服务端 下载并移动文件； wget https://github.com/fatedier/frp/releases/download/v0.29.0/frp_0.29.0_linux_amd64.tar.gz # 如果系统未" />
    

    
    
    <meta name="keywords" content="Hugo, theme, zozo" />
    

	
    
    <link rel="shortcut icon" href="https://gojun.me/images/favicon.ico" />

    <link rel="stylesheet" type="text/css" media="screen" href="https://gojun.mecss/normalize.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://cdn.jsdelivr.net/npm/animate.css@4.1.0/animate.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://gojun.me/css/zozo.css" />
	<link rel="stylesheet" type="text/css" media="screen" href="https://cdn.jsdelivr.net/npm/remixicon@2.5.0/fonts/remixicon.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://gojun.me/css/highlight.css" />

    
    
</head>

<body>
    <div class="main animate__animated animate__fadeInDown">
        <div class="nav_container animated fadeInDown">
    <div class="site_nav" id="site_nav">
        <ul>
            
            <li>
                <a href="/">Home</a>
            </li>
            
            <li>
                <a href="/posts/">Archive</a>
            </li>
            
            <li>
                <a href="/tags/">Tags</a>
            </li>
            
            <li>
                <a href="/projects/">Projects</a>
            </li>
            
        </ul>
    </div>
    <div class="menu_icon">
        <a id="menu_icon"><i class="ri-menu-line"></i></a>
    </div>
</div>
        <div class="header animated fadeInDown">
    <div class="site_title_container">
        <div class="site_title">
            <h1>
                <a href="https://gojun.me">
                    <span>GoJun</span>
                </a>
            </h1>
        </div>
        <div class="description">
            <p class="sub_title">为向往生活努力奋斗！</p>
            <div class="my_socials">
                
                
                <a href="https://github.com/freelander" title="github" target="_blank"><i class="ri-github-fill"></i></a>
                
                
                <a href="https://gojun.me/index.xml" type="application/rss+xml" title="rss" target="_blank"><i
                        class="ri-rss-fill"></i></a>
            </div>
        </div>
    </div>
</div>
        <div class="content">
            <div class="post_page">
                <div class="post animate__animated animate__fadeInDown">
                    <div class="post_title post_detail_title">
                        <h2><a href='/posts/jenkins-frp/'>如何利用 frp 实现 Mac 的内网穿透</a></h2>
                        <span class="date">2019.09.23</span>
                    </div>
                    <div class="post_content markdown"><p>这里服务端我用的是阿里云的轻量应用服务器，系统配置的 Ubuntu18.04；客户端是自己开发的 Mac 电脑。</p>
<p>下面记录的是如何利用 frp 来实现本地的 web 端口可以使用外网来访问。</p>
<h2 id="服务端">服务端</h2>
<ol>
<li>下载并移动文件；</li>
</ol>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback">wget https://github.com/fatedier/frp/releases/download/v0.29.0/frp_0.29.0_linux_amd64.tar.gz
# 如果系统未安装 wget，可以先安装 wget
yum -y install wget

# 解压 frp 包
tar -zxvf frp_0.29.0_linux_amd64.tar.gz
# 重新命名文件夹为 frp
mv frp_0.29.0_linux_amd64 frp
</code></pre></div><ol start="2">
<li>给运行文件赋予权限，并修改配置文件</li>
</ol>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback">cd frp
chmod +x frps
# 编辑服务器配置文件
vim frps.ini
</code></pre></div><ol start="3">
<li>以下为 frps.ini 配置</li>
</ol>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback">[common]
bind_port = 7000
auto_token=12345678
vhost_http_port = 8080
vhost_https_port = 443

dashboard_port = 7500
# dashboard 用户名密码，默认都为 admin
dashboard_user = admin
dashboard_pwd = admin
</code></pre></div><h3 id="使用supervisor设置开机自启-安装-supervisor">使用supervisor设置开机自启, 安装 supervisor</h3>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback">apt-cache search supervisor
apt-get install supervisor
</code></pre></div><p><strong>安装 Supervisor 报错</strong></p>
<div class="highlight"><pre class="chroma"><code class="language-go" data-lang="go"><span class="nx">Reading</span> <span class="kn">package</span> <span class="nx">lists</span><span class="o">...</span> <span class="nx">Done</span>
<span class="nx">Building</span> <span class="nx">dependency</span> <span class="nx">tree</span>       
<span class="nx">Reading</span> <span class="nx">state</span> <span class="nx">information</span><span class="o">...</span> <span class="nx">Done</span>
<span class="nx">E</span><span class="p">:</span> <span class="nx">Unable</span> <span class="nx">to</span> <span class="nx">locate</span> <span class="kn">package</span> <span class="nx">supervisor</span>
</code></pre></div><p>查询资料后，发现是是apt需要更新</p>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback">sudo apt-get update
</code></pre></div><ol start="8">
<li>创建并编辑 frp.conf 设置开机自启</li>
</ol>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback">cd /etc/supervisor/conf.d/
touch frp.conf
vim frp.conf

# 以下为 frp.conf 配置
[program:frp]
command = /root/frp/frps -c /root/frp/frps.ini 
autostart = true
autorestart = true
startsecs=0

# systemctl 查看开机启动项
systemctl list-unit-files | grep supervisor
</code></pre></div><ol start="9">
<li>访问 服务端ip:7500，查看服务端是否配置成功</li>
</ol>
<p>配置成功是可以看到</p>
<p>如果访问不成功，阿里云服务器后台检查防火墙配置，需要添加刚才两个端口到规则里面</p>
<p>

<div class="fancybox">
<a data-fancybox="demo" href="/images/2019/09/06.png">
<img src="/images/2019/09/06.png" alt="image"  />
</a>
</div>

</p>
<h2 id="客户端">客户端</h2>
<p>客户端和服务端的版本号要一致，另外 Mac 下载的是 darwin_amd64 这个格式，<a href="https://github.com/fatedier/frp/releases/download/v0.29.0/frp_0.29.0_darwin_amd64.tar.gz">下载地址</a>。</p>
<ol>
<li>下载文件回来后通过命令解压并移动文件；</li>
</ol>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback"># 解压并移动文件夹
tar zxvf frp_0.29.0_darwin_amd64.tar.gz
# 在 /usr/local/bin 目录下创建一个 frpc 文件夹
mkdir /usr/local/bin/frpc
# 将刚才解压的文件内容移动
mv frp_0.27.0_darwin_amd64/* /usr/local/bin/frpc
# 删除压缩包
rm -rf frp_0.29.0_darwin_amd64
</code></pre></div><ol start="2">
<li>给运行文件权限，并编辑配置文件；</li>
</ol>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback">cd /usr/local/bin/frpc
# 赋予权限
chmod +x frpc
# 修改配置文件
vim frpc.ini
</code></pre></div><ol start="3">
<li>下面为 frpc.ini 配置。</li>
</ol>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback">[common]
# 这里修改为 frp 服务端的 ip 地址
server_addr = x.x.x.x
# 与服务端绑定的进行通信的端口，跟服务端配置的端口一致
server_port = 7000
auto_token = 123456

[jenkins]
type = http
# 本地映射的端口，比如开了个tomcat apache，端口为8080
local_port = 8080
# 域名必须要有，并解析到你的服务器地址
# 记得域名要解析到服务器地址，否则会穿透失败
custom_domains = test.com
</code></pre></div><h3 id="配置-frpcplist-实现开机自启">配置 frpc.plist 实现开机自启</h3>
<ol>
<li>创建开机自启文件并编辑；</li>
</ol>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback">touch ~/Library/LaunchAgents/frpc.plist
vim ~/Library/LaunchAgents/frpc.plist
</code></pre></div><ol start="2">
<li>以下为 frpc.plist 配置；</li>
</ol>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback">&lt;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&gt;
&lt;!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd &gt;
&lt;plist version=&#34;1.0&#34;&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;frpc&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
         &lt;string&gt;/usr/local/bin/frpc/frpc&lt;/string&gt;
         &lt;string&gt;-c&lt;/string&gt;
         &lt;string&gt;/usr/local/bin/frpc/frpc.ini&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;KeepAlive&lt;/key&gt;
    &lt;true/&gt;
    &lt;key&gt;RunAtLoad&lt;/key&gt;
    &lt;true/&gt;
&lt;/dict&gt;
&lt;/plist&gt;
</code></pre></div><ol start="3">
<li>加载生效。</li>
</ol>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback"># 赋权限
sudo chown root ~/Library/LaunchAgents/frpc.plist
# 启动
sudo launchctl load -w ~/Library/LaunchAgents/frpc.plist
</code></pre></div><h2 id="测试">测试</h2>
<p>验证是否穿透成功，在浏览器输入上文配置的域名，比如 test.com:8080 ，如果能访问即配置成功。</p>
<h2 id="参考资料">参考资料</h2>
<ul>
<li><a href="https://blog.csdn.net/zengd0/article/details/79522253">搭建frp实现内网穿透</a></li>
<li><a href="https://streamelody.github.io/2019/05/mac-frp-tutorial/">Mac 下使用 FRP 实现内网穿透</a></li>
<li><a href="https://zhuanlan.zhihu.com/p/42574259">阿里DNS：DNS迁移到阿里云，这一篇就够了</a></li>
<li><a href="https://dns.console.aliyun.com/#/dns/domainList">阿里云 域名解析</a></li>
</ul>
</div>
                    <div class="post_footer">
                        
                        <div class="meta">
                            <div class="info">
                                <span class="field tags">
                                    <i class="ri-stack-line"></i>
                                    
                                    <a href="https://gojun.me/tags/jenkins/">Jenkins</a>
                                    
                                </span>
                            </div>
                        </div>
                        
                    </div>
                </div>
                
                
                <div class="doc_comments"></div>
                
            </div>
        </div>
    </div>
    <a id="back_to_top" href="#" class="back_to_top"><i class="ri-arrow-up-s-line"></i></a>
    <footer class="footer">
    <div class="footer_slogan">
        <span></span>
    </div>
</footer>
    <script src="https://gojun.me/js/jquery-3.5.1.min.js"></script>
<link href="https://gojun.me/css/fancybox.min.css" rel="stylesheet">
<script src="https://gojun.me/js/fancybox.min.js"></script>
<script src="https://gojun.me/js/zozo.js"></script>


<script type="text/javascript" async
    src="https://cdn.bootcss.com/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
        MathJax.Hub.Config({
            tex2jax: {
                inlineMath: [['$', '$'], ['\\(', '\\)']],
                displayMath: [['$$', '$$'], ['\[\[', '\]\]']],
                processEscapes: true,
                processEnvironments: true,
                skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
                TeX: {
                    equationNumbers: { autoNumber: "AMS" },
                    extensions: ["AMSmath.js", "AMSsymbols.js"]
                }
            }
        });

        MathJax.Hub.Queue(function () {
            
            
            
            var all = MathJax.Hub.getAllJax(), i;
            for (i = 0; i < all.length; i += 1) {
                all[i].SourceElement().parentNode.className += ' has-jax';
            }
        });
    </script>

<style>
    code.has-jax {
        font: inherit;
        font-size: 100%;
        background: inherit;
        border: inherit;
        color: #515151;
    }
</style>



<script type="application/javascript">
var doNotTrack = false;
if (!doNotTrack) {
	window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
	ga('create', 'UA-142037913-1', 'auto');
	
	ga('send', 'pageview');
}
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>

</body>

</html>